#include "all.h"


//1毫秒定时器
void TIM2_Init(void)
{
	TIM_TimeBaseInitType  TIM_TimeBaseStructure;
	NVIC_InitType NVIC_InitStructure;

	//总线使能
	RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM2, ENABLE);//使能低速总线时钟

	//优先级
	NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;//0;PCY
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	//时钟配置
	TIM_TimeBaseStructure.Period = (40 - 1);           // 自动重装载寄存器周期的值(计数值) 
	TIM_TimeBaseStructure.Prescaler = (1800 - 1);	  //时钟预分频数,1秒4000次 
	TIM_TimeBaseStructure.ClkDiv = 0;			  
	TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP;//向上计数模式

	TIM_InitTimeBase(TIM2, &TIM_TimeBaseStructure);

	TIM_ClearFlag(TIM2, TIM_FLAG_UPDATE);			        // 清除溢出中断标志 
	TIM_ConfigInt(TIM2,TIM_INT_UPDATE,ENABLE);
	TIM_Enable(TIM2, ENABLE);
}



/*1MS定时*/
void TIM2_IRQHandler(void)
{
	if (TIM_GetIntStatus(TIM2, TIM_INT_UPDATE) != RESET)
	{
		TIM_ClrIntPendingBit(TIM2,TIM_FLAG_UPDATE);
		/*Key*/
		Key_Time(); 	
		if(KEY_s.x==0x00000000)Time_Auto.Ms++;	
		NRF24L01_time();			   //NRF24L01定时计时
		LED_Time_Task();	 		
	}
}



